﻿@{
	Layout = null;
}

<link href="~/libs/layui-v2.9.21/layui-v2.9.21/layui/css/layui.css" rel="stylesheet" />

<form class="layui-form" action="">
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">通知单编号</label>
			<div class="layui-input-inline layui-input-wrap">
				<input type="text" id="inboundListCode" name="inboundListCode" lay-verify="required" placeholder="请输入通知单编号" class="layui-input">
			</div>
			<div class="layui-form-mid">
				<input type="checkbox" lay-skin="switch" lay-filter="switchTest">自动生成
			</div>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">通知单名称</label>
		<div class="layui-input-block">
			<input type="text" name="notifiName" style="width:250px;" lay-verify="required" placeholder="请输入通知单名称" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item layui-form-text" style="width:350px;">
		<label class="layui-form-label">供应商</label>
		<div class="layui-input-block">
			<select name="suppliersname" id="suppername" lay-verify="required" lay-filter="suppername">
				<option value="">请选择供应商</option>
			</select>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">到货日期</label>
		<div class="layui-input-block">
			<input type="date" style="width:250px;" name="arrivalTime" id="date" lay-verify="date" placeholder="年-月-日" class="layui-input">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">单据状态</label>
		<div class="layui-input-block">
			<input type="radio" name="nState" value="1" title="待质检" checked>
			<input type="radio" name="nState" value="2" title="待入库">
			<input type="radio" name="nState" value="3" title="草稿">
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
			<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</div>
	</div>
</form>

<script src="~/libs/jquery/jquery.js"></script>
<script src="~/libs/layui-v2.9.21/layui-v2.9.21/layui/layui.js"></script>
<script>
	layui.use(['form', 'laydate'], function(){
	  var form = layui.form;
	  var layer = layui.layer;
	  var laydate = layui.laydate;

	  // 指定开关事件,生成车间编码
	  form.on('switch(switchTest)', function(data){
		  if(data.elem.checked){
			  var dates=new Date();
			  var nums=dates.getFullYear()+(dates.getMonth()+1).toString().padStart(2,'0')+dates.getDate().toString().padStart(2,'0');
			  var random=Math.floor(Math.random()*10)+'';
			  for(var i=0;i<2;i++){
				  random+=Math.floor(Math.random()*10);
			  }
			  random='AN'+nums+random;
			  $("#inboundListCode").val(random);
		  }else{
			  $('input[name="inboundListCode"]').val('');
		  }

	  });

	  //就绪函数
	  $(function(){
		  GetSuppernames()
	  })

	  //下拉框
	  function GetSuppernames(){
		  $.ajax({
			  url:'/Puffs/GetSupperdatas',
			  type:'get',
			  dataType:'json',
			  async:false,
			  success:function(res){
				  $(res.data).each(function(obj){
					  $("#suppername").append('<option value="'+this.supplierName+'">'+this.supplierName+'</option>')
				  })
				  layui.form.render();
			  }
		  })
	  }

	  // 提交事件
	  form.on('submit(demo1)', function(data){
		var field = data.field; // 获取表单字段值
		$.ajax({
		   url:'/puffs/AddNotidatas',
		   data:field,
		   type:'post',
		   dataType:'json',
		   success:res=>{
			   if (res > 0) {
				  //layer信息提示
				  layer.alert('添加成功');//下面是关键代码
				  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
				  window.parent.location.reload(); // 刷新父页
				  parent.layer.close(index); //再执行关闭
				  setTimeout(function () { parent.layer.close(index) }, 30000);//延迟s
			   }
			   else {
				  layer.msg("添加失败！");
			   }
		   }
		})
		return false; // 阻止默认 form 跳转
	  });
	});
</script>


